import JSZip from 'jszip'
export default {
  methods: {
    async downloadByZip(fileList) {
      const zip = new JSZip()
      for (let i = 0; i < fileList.length; i++) {
        const blob = await this.$store.dispatch(
          'downloadFileTbNetDisk',
          fileList[i].id,
        )
        zip.file(fileList[i].oldName, blob, { base64: true })
      }
      zip.generateAsync({ type: 'blob' }).then((content) => {
        location.href = URL.createObjectURL(content)
      })
    },
    getImgBlob(url) {
      return new Promise((resolve) => {
        const xhr = new XMLHttpRequest()
        xhr.open('get', url, true)
        xhr.responseType = 'blob'
        xhr.onload = () => {
          resolve(xhr.response)
        }
        xhr.send()
      })
    },
    //数据分组
    getGroup(data, key) {
      let groups = {}
      data.forEach((c) => {
        let value = c[key]
        groups[value] = groups[value] || []
        groups[value].push(c)
      })
      return groups
    },
  },
}
